'use strict';

goog.provide('Blockly.Arduino.rfid');
goog.require('Blockly.Arduino');
Blockly.Arduino.forBlock['rfid_init'] = function(block) {
    Blockly.Arduino.definitions_['include_ESP32rfid'] = '#include <MFRC522_I2C.h>';
    Blockly.Arduino.setups_['setup_ESP32rfid'] = `rfid.PCD_Init();`;
    var code = ``;
    return code;
};

Blockly.Arduino.forBlock['rfid_detect'] = function(block) {
    var doCode = Blockly.Arduino.statementToCode(block, 'rfidDO');
    var code = `if((rfid.PICC_IsNewCardPresent()==MFRC522::STATUS_OK && rfid.PICC_ReadCardSerial()==MFRC522::STATUS_OK)){\n${doCode}\n}`;
    return code;
};

Blockly.Arduino.forBlock['rfid_read'] = function(block) {
    var code = `rfid.readUid()`;
    return [code, Blockly.Arduino.ORDER_ATOMIC];
};